// pages/my/my.js
var app = getApp();
Page({
  data: {
    shipHidden: true,
    receiptHidden: true,
    valueHidden: true,
    afterSaleHidden: true,
  },
  onShareAppMessage: function (res) {
    return {
      title: '成都皮肤美容微整',
      path: '/pages/homepage/homepage?id=' + wx.getStorageSync("userid"),
    }
  },
  onLoad: function (options) {
    app.showShareMenus();
    if (options.id){
      app.globalData.referrerId = options.id
   }
    var pages2 = getCurrentPages()    //获取加载的页面
    var currentPage = pages2[pages2.length - 1]    //获取当前页面的对象
    //var url = currentPage.route    //当前页面url
    var sss = currentPage.route.split("pages/")[1]
    var bbb=sss.split("/")[0]
    var that = this
    wx.getSystemInfo({//获取滑块的高宽
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
  },
   
  onReady: function () {
    // 页面渲染完成
  },

  onShow: function () {
    // 页面显示
    this.setData({
      userInfo: wx.getStorageSync('userInfo'),
    });
    this.setData({
      shipHidden: true,
      receiptHidden: true,
      valueHidden: true,
      afterSaleHidden: true
    })
    var that = this;
    getOrderNums(that);
  },
  spikeGroup: function () {
    wx.navigateTo({
      url: '../ticket/ticket',
      success: function (res) {
        // success
      }
    })
  },
  chooseAddress: function () {
    /*wx.navigateTo({
      url: '/pages/directAddress/directAddress?click=1',
      success: function(res){
        // success
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    })*/
    var that =this;
    wx.chooseAddress({
      success: function (res) {
        console.log(res.userName)
        console.log(res.postalCode)
        console.log(res.provinceName)
        console.log(res.cityName)
        console.log(res.countyName)
        console.log(res.detailInfo)
        console.log(res.nationalCode)
        console.log(res.telNumber)
        var address={
          name: res.userName,
          phone: res.telNumber,
          address: res.provinceName + res.cityName + res.countyName + res.detailInfo,
        }
        wx.setStorageSync('userAddress', address)
      }
    })
  }
  ,
  calling: function (e) {
    wx.makePhoneCall({
      phoneNumber: ''+e.target.id, //此号码并非真实电话号码，仅用于测试
    })
  },
  myDistribution:function(){//我的分销
    wx.navigateTo({

      url: '/pages/Distribution/Distribution',
    })
  }, aboutUs:function(){
    wx.navigateTo({
      url: '/pages/index/index',
    })
  },formSubmit:function(e){
    wx.showModal({
      title: e.detail.formId+"",
      content: '',
    })
  }
  ,
  getOrders:function(){
    wx.navigateTo({
      url: '../../pages/hostOrder/hostOrder',
    })
  }
  , myPink:function(){
    wx.navigateTo({
      url: '../../pages/myPink/myPink',
    })
  }
})




function getOrderNums(that){
  wx.request({
    url: app.globalData.allUrl + "/orderr/order_count",
    data: {
      user_id: wx.getStorageSync('userid')
    },
    header: { 'content-type': "application/x-www-form-urlencoded" },
    method: 'POST',
    success: function (res) {
     //  console.log(res.data)
       
       if (res.data.delivery > 0) {//判断订单类型
         that.setData({//将订单类型对应的数量显示在页面中
           shipHidden: false,
           shipData: res.data.delivery
         })
       }
       if (res.data.shipped > 0) {
         that.setData({//将订单类型对应的数量显示在页面中
           receiptHidden: false,
           receiptData: res.data.shipped
         })
       }
      /* if(res.data.role.role=='1'){
         that.setData({
           isAgent:false
         })
       } else if(res.data.role.role=='2'){
         that.setData({
           isAgent: true
         })
       }
       if(res.data.role.shop_id){
         wx.setStorageSync("shopid", res.data.role.shop_id)
       }*/
    }
  })
}